package com.igeek.web;

import com.igeek.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author jerryHe
 * @create 2019-10-08 15:59
 */

@WebServlet("/checkUsernameServlet")
public class CheckUsernameServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        UserService service = new UserService();
        boolean isExist =  service.checkUsername(username);
        String jsonString = "{\"isExist\":"+isExist+"}";
        System.out.println(jsonString);
        response.getWriter().write(jsonString);

    }
}
